﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System.Runtime.Serialization;
using System;
using System.ComponentModel;
using BrainTechLLC.ThreadSafeObjects;

#if USE_HYPER
using Hyper.ComponentModel;
#endif

namespace BrainTechLLC
{
    public static partial class Lookups
    {
        public static ThreadSafeLookupOnDemand<string, Observable> ObservableMethods = new ThreadSafeLookupOnDemand<string, Observable>();
        public static ThreadSafeLookupOnDemand<string, Observable> ObservableProperties = new ThreadSafeLookupOnDemand<string, Observable>();
    }

#if NO_SILVERLIGHT
    [TypeDescriptionProvider(typeof(HyperTypeDescriptionProvider))]
#endif
    [Serializable]
    [DataContract]
    public class Observable
    {
        [DataMember]
        public string ObservableIdentifier { get; set; }

        [field: NonSerialized]
        public event EventHandler<ObjectEventArgs<object, object, object, object, object>> NotifyObservers;

        public void RaiseNotify(object o1, object o2, object o3, object o4, object o5)
        {
            if (NotifyObservers != null)
                NotifyObservers(this, new ObjectEventArgs<object, object, object, object, object>(o1, o2, o3, o4, o5));
        }
    }

#if NO_SILVERLIGHT
    [TypeDescriptionProvider(typeof(HyperTypeDescriptionProvider))]
#endif
    [Serializable]
    [DataContract]
    public class Observable<T1> where T1 : class
    {
        public string ObservableIdentifier { get; set; }

        [field: NonSerialized]
        public event EventHandler<ObjectEventArgs<T1>> NotifyObservers;

        public void RaiseNotify(T1 o1)
        {
            if (NotifyObservers != null)
                NotifyObservers(this, new ObjectEventArgs<T1>(o1));
        }
    }

#if NO_SILVERLIGHT
    [TypeDescriptionProvider(typeof(HyperTypeDescriptionProvider))]
#endif
    [Serializable]
    [DataContract]
    public class Observable<T1, T2>
        where T1 : class
        where T2 : class
    {
        public string ObservableIdentifier { get; set; }

        [field: NonSerialized]
        public event EventHandler<ObjectEventArgs<T1, T2>> NotifyObservers;

        public void RaiseNotify(T1 o1, T2 o2)
        {
            if (NotifyObservers != null)
                NotifyObservers(this, new ObjectEventArgs<T1, T2>(o1, o2));
        }
    }

#if NO_SILVERLIGHT
    [TypeDescriptionProvider(typeof(HyperTypeDescriptionProvider))]
#endif
    [Serializable]
    [DataContract]
    public class Observable<T1, T2, T3>
        where T1 : class
        where T2 : class
        where T3 : class
    {
        public string ObservableIdentifier { get; set; }

        [field: NonSerialized]
        public event EventHandler<ObjectEventArgs<T1, T2, T3>> NotifyObservers;

        public void RaiseNotify(T1 o1, T2 o2, T3 o3)
        {
            if (NotifyObservers != null)
                NotifyObservers(this, new ObjectEventArgs<T1, T2, T3>(o1, o2, o3));
        }
    }

#if NO_SILVERLIGHT
    [TypeDescriptionProvider(typeof(HyperTypeDescriptionProvider))]
#endif
    [Serializable]
    [DataContract]
    public class Observable<T1, T2, T3, T4>
        where T1 : class
        where T2 : class
        where T3 : class
        where T4 : class
    {
        public string ObservableIdentifier { get; set; }

        [field: NonSerialized]
        public event EventHandler<ObjectEventArgs<T1, T2, T3, T4>> NotifyObservers;

        public void RaiseNotify(T1 o1, T2 o2, T3 o3, T4 o4)
        {
            if (NotifyObservers != null)
                NotifyObservers(this, new ObjectEventArgs<T1, T2, T3, T4>(o1, o2, o3, o4));
        }
    }

#if NO_SILVERLIGHT
    [TypeDescriptionProvider(typeof(HyperTypeDescriptionProvider))]
#endif
    [Serializable]
    [DataContract]
    public class Observable<T1, T2, T3, T4, T5>
        where T1 : class
        where T2 : class
        where T3 : class
        where T4 : class
        where T5 : class
    {
        public string ObservableIdentifier { get; set; }

        [field: NonSerialized]
        public event EventHandler<ObjectEventArgs<T1, T2, T3, T4, T5>> NotifyObservers;

        public void RaiseNotify(T1 o1, T2 o2, T3 o3, T4 o4, T5 o5)
        {
            if (NotifyObservers != null)
                NotifyObservers(this, new ObjectEventArgs<T1, T2, T3, T4, T5>(o1, o2, o3, o4, o5));
        }
    }


}

